package com.ruoyi.dzzh.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dzzh.domain.DzzhTask;
import com.ruoyi.dzzh.service.IDzzhTaskService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 巡查任务Controller
 * 
 * @author cjt
 * @date 2023-03-17
 */
@RestController
@RequestMapping("/dzzh/task")
public class DzzhTaskController extends BaseController
{
    @Autowired
    private IDzzhTaskService dzzhTaskService;

    /**
     * 查询巡查任务列表
     */
    @PreAuthorize("@ss.hasPermi('dzzh:task:list')")
    @GetMapping("/list")
    public TableDataInfo list(DzzhTask dzzhTask)
    {
        startPage();
        List<DzzhTask> list = dzzhTaskService.selectDzzhTaskList(dzzhTask);
        return getDataTable(list);
    }

    /**
     * 导出巡查任务列表
     */
    @PreAuthorize("@ss.hasPermi('dzzh:task:export')")
    @Log(title = "巡查任务", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DzzhTask dzzhTask)
    {
        List<DzzhTask> list = dzzhTaskService.selectDzzhTaskList(dzzhTask);
        ExcelUtil<DzzhTask> util = new ExcelUtil<DzzhTask>(DzzhTask.class);
        util.exportExcel(response, list, "巡查任务数据");
    }

    /**
     * 获取巡查任务详细信息
     */
    @PreAuthorize("@ss.hasPermi('dzzh:task:query')")
    @GetMapping(value = "/{taskId}")
    public AjaxResult getInfo(@PathVariable("taskId") Long taskId)
    {
        return AjaxResult.success(dzzhTaskService.selectDzzhTaskByTaskId(taskId));
    }

    /**
     * 新增巡查任务
     */
    @PreAuthorize("@ss.hasPermi('dzzh:task:add')")
    @Log(title = "巡查任务", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DzzhTask dzzhTask)
    {
        return toAjax(dzzhTaskService.insertDzzhTask(dzzhTask));
    }

    /**
     * 修改巡查任务
     */
    @PreAuthorize("@ss.hasPermi('dzzh:task:edit')")
    @Log(title = "巡查任务", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DzzhTask dzzhTask)
    {
        return toAjax(dzzhTaskService.updateDzzhTask(dzzhTask));
    }

    /**
     * 删除巡查任务
     */
    @PreAuthorize("@ss.hasPermi('dzzh:task:remove')")
    @Log(title = "巡查任务", businessType = BusinessType.DELETE)
	@DeleteMapping("/{taskIds}")
    public AjaxResult remove(@PathVariable Long[] taskIds)
    {
        return toAjax(dzzhTaskService.deleteDzzhTaskByTaskIds(taskIds));
    }
}
